package com.springapi.service.impl;

import com.springapi.entity.App;
import com.springapi.dao.AppDao;
import com.springapi.service.AppService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (App)表服务实现类
 *
 * @author makejava
 * @since 2024-12-04 14:37:55
 */
@Service("appService")
public class AppServiceImpl implements AppService {
    @Resource
    private AppDao appDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public App queryById(Integer id) {
        return this.appDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param app 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<App> queryByPage(App app, PageRequest pageRequest) {
        long total = this.appDao.count(app);
        return new PageImpl<>(this.appDao.queryAllByLimit(app, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param app 实例对象
     * @return 实例对象
     */
    @Override
    public App insert(App app) {
        this.appDao.insert(app);
        return app;
    }

    /**
     * 修改数据
     *
     * @param app 实例对象
     * @return 实例对象
     */
    @Override
    public App update(App app) {
        this.appDao.update(app);
        return this.queryById(app.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.appDao.deleteById(id) > 0;
    }
}
